const path = require("path");

function resolve(dir) {
  return path.join(__dirname, dir);
}

module.exports = {
  chainWebpack: (config) => {
    // 由于我们修改了渲染进程目录，修改'@'的alias
    config.resolve.alias.set("@", resolve("src/renderer"));
  },
  pages: {
    index: {
      entry: "src/renderer/main.js",
      template: "public/index.html",
      filename: "index.html",
      title: "vue-cli-electron",
      chunks: ["chunk-vendors", "chunk-common", "index"],
    },
    // loader: 'src/loader/main.js' // 多页loader页
  },
  pluginOptions: {
    electronBuilder: {
      mainProcessFile: "src/main/index.js", // 主进程入口文件
      mainProcessWatch: ["src/main"], // 检测主进程文件在更改时将重新编译主进程并重新启动
    },
    // builderOptions是electron的打包配置:(参考=>https://www.electron.build/configuration/configuration)
    builderOptions: {
      appId: process.env.VUE_APP_APPID,
      productName: process.env.VUE_APP_PRODUCTNAME,
      // 本来electron的name及version是读取package.json里面的值的,这里使用extraMetadata把这两个值注入进package.json
      extraMetadata: {
        name: process.env.VUE_APP_APPID.split(".").pop(),
        version: process.env.VUE_APP_VERSION,
      },
      asar: true,
      directories: {
        output: "dist_electron",
        buildResources: "build",
        app: "dist_electron/bundled",
      },
      files: [
        {
          filter: ["**"],
        },
      ],
      extends: null,
      electronVersion: "11.3.0",
      extraResources: [],
      electronDownload: {
        mirror: "https://npm.taobao.org/mirrors/electron/",
      },
      dmg: {
        contents: [
          {
            type: "link",
            path: "/Applications",
            x: 410,
            y: 150,
          },
          {
            type: "file",
            x: 130,
            y: 150,
          },
        ],
      },
      mac: {
        icon: "public/icons/icon.icns",
      },
      nsis: {
        oneClick: false,
        perMachine: true,
        allowToChangeInstallationDirectory: true,
        warningsAsErrors: false,
        allowElevation: false,
        createDesktopShortcut: true,
        createStartMenuShortcut: true,
      },
      win: {
        target: "nsis",
        icon: "public/icons/icon.ico",
        requestedExecutionLevel: "highestAvailable",
      },
      linux: {
        icon: "public/icons",
      },
      publish: {
        provider: "generic",
        url: "http://127.0.0.1",
      },
    },
  },
};
